package csl.mq.rabbitmq.old.test;

import csl.mq.rabbitmq.entity.MyMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.*;


/**
 * @Description: TODO 消费者
 * @author: 隔山海
 * @date: 2021年08月31日 20:44
 */
@Slf4j
//@Component
public class Consumer {

    /*直连*/
    @RabbitListener(queuesToDeclare = @Queue("send"))
    public void receiveMessage(String message){
      log.error("message====>{}",message);
    }

    /*Work Queue*/
    @RabbitListener(queuesToDeclare = @Queue("workqueue"))
    public void receiveWorkQueue1(String message){
        log.error("workQueue1=====>{}",message);
    }
    @RabbitListener(queuesToDeclare = @Queue("workqueue"))
    public void receiveWorkQueue2(String message){
        log.error("workQueue2=====>{}",message);
    }

    /*Fanout*/
    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue,  //临时队列
                    exchange = @Exchange(name = "fanout",type = "fanout") //绑定交换机类型
            )
    )
    public void receiveFanout1(String message){
        log.error("fanout1=====>{}",message);
    }
    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue, //临时队列
                    exchange = @Exchange(
                            name = "fanout",
                            type = "fanout") //绑定交换机类型
            )
    )
    public void receiveFanout2(String message){
        log.error("fanout2=====>{}",message);
    }

    /*routing direct*/
    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(),
                    key = {"info","error"},
                    exchange = @Exchange(name = "directs"
                    )
            )
    )
    public void receiveDirect1(String message){
        log.error("Direct1=====>{}",message);
    }
    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(),
                    key = {"error"},
                    exchange = @Exchange(name = "directs"
                    )
            )
    )
    public void receiveDirect2(String message){
        log.error("Direct2=====>{}",message);
    }


    /*routing topic*/
    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue,
                    key = "{user.*}",
                    exchange = @Exchange(
                            type = "topic",
                            name = "topics"
                    )
            )
    )
    public void receiveTopic1(String message){
        log.error("Topic1=====>{}",message);
    }
    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue,
                    key = "{user.#}",
                    exchange = @Exchange(
                            type = "topic",
                            name = "topics"
                    )
            )
    )
    public void receiveTopic2(String message){
        log.error("Topic2=====>{}",message);
    }

    /*消息监视消费*/
    @RabbitListener(
            bindings = {
                    @QueueBinding(
                            value = @Queue,
                            key = "{confirmError}",
                            exchange = @Exchange(name = "confirm"))
            }
    )
    public void receiveConfirm(MyMessage c){
        log.info("c====>{}",c);
    }
}
